package com.example.jsnative;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
/**
 * @author: wzq
 * @date: 14-6-11
 * description: change it at File | setting | File and code templates | include | file header
 */
public class PluginCalendar extends CordovaPlugin {
    public static final String ACTION_ADD_CALENDAR_ENTRY = "addCalendarEntry";

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        System.out.println("PluginCalendar::execute");
        checkParam(action, args, callbackContext);
        //
        if(ACTION_ADD_CALENDAR_ENTRY.equals(action)) {
            String result = "greeting from PluginCalendar::execute";
            callbackContext.success(result);
            return true;
        } else {
            callbackContext.error("PluginCalendar action must be "+ACTION_ADD_CALENDAR_ENTRY);
            return false;
        }
    }

    private void checkParam(String action, JSONArray args, CallbackContext callbackContext) {
        StringBuilder sb = new StringBuilder();
        //
        sb.append("checkParam\n");
        sb.append("action=" + action + "\n");
        sb.append("args=" + args.toString() + "\n");
        sb.append("callbackContext=" + callbackContext + "\n");
        //
        System.out.println(sb.toString());
    }
}
